<?php

namespace Logic\Store;
use Core\Exception;
use Validator\BaseValidator;

class StoreLogic
{

    function __construct()
    {

    }


    /**
     * 获取某店铺中心基本数据
     * @param $storeId
     * @return array
     * @throws Exception
     */
    public function getStoreDetail($params = [],$userId = ''){
        $rules = [
            'storeId' => 'require|isNumber',
        ];
        (new BaseValidator())->validate($params, $rules);

        $store = (new \StoreModel())->getOneData(['id' => $params['storeId'], 'store_status' => 'PASSED','is_logoff'=>0]);
        if (empty($store)){
            throw new Exception(10163);
        }

        $data = [
            'store'             => $store,                              //店铺信息
            'is_my_store'       => $store['userId'] == $userId ? 1 : 0, //是否当前用户的店铺， 1是 0否
        ];
        return $data;
    }
    //更细店铺信息
    public function updateStroe($params,$userInfo){
        $data = [
            'logoImg' => $params['logoImage']?$params['logoImage']:'',
            'mainBuiness' => $params['mainBuiness']?$params['mainBuiness']:''
        ];
        $data = array_filter($data);
        $result = (new \StoreModel())->where('userId',$userInfo['id'])->update($data);
        if ($result>0){
            return true;
        }else{
            throw new Exception(10180);
        }
    }

}